package com.zhkj.crawl;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.HexUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.http.HttpRequest;

import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;

public class d3 {
    public static void main(String[] args) throws Exception {
        String host = "http://open-api.fannoshop.com";
        long timestamp = DateUtil.currentSeconds();
        String appKey = "4olrl0";
        String appSecret = "ace42c3bdc564aceee10586497df83ee2a5ae253";
        String path = "/api/shop/get_authorized_shop";
        String params = String.format("app_key%stimestamp%s", appKey, timestamp);
//        String params = "app_key" + appKey + "timestamp" + timestamp;
        String accessToken = "OkY2ZHpIvUltGe0guaq9B6xu_2RQMI4amGJ_GfOVcRdnyJ4DTG4VElRq9lIk7efb";
        String signSource = appSecret + path + params + appSecret;

        System.out.println(timestamp);
        System.out.println(signSource);
        // 26124abdd862f6e4b6f7b04a4a1f8f44caed9ac73aad0a72d63b31e74c70f243

        Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
        SecretKeySpec secretKey = new SecretKeySpec(appSecret.getBytes(), "HmacSHA256");
        sha256_HMAC.init(secretKey);
        byte[] hash = sha256_HMAC.doFinal(signSource.getBytes());
        String sign1 = HexUtil.encodeHexStr(hash);
        System.out.println(sign1);

        String url = String.format("%s%s?app_key=%s&access_token=%s&sign=%s&timestamp=%s",
                host, path, appKey, accessToken, sign1, timestamp);
        String response = HttpRequest.get(url).contentType("application/json")
                .execute()
                .body();

        System.out.println(response);
    }



}
